/**
 * 
 */
package com.telenav.techtalk;

import com.telenav.techtalk.ColorMatrixActivity.ColorMatrixView;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import android.graphics.SweepGradient;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

/**
 * @author yxyao
 *
 */
public class ShaderRoundRectActivity extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new ShaderRoundRectView(this), new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    }
    
    class ShaderRoundRectView extends View{

        /**
         * @param context
         */
        public ShaderRoundRectView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
        
        protected void onDraw(Canvas canvas) {
           LinearGradient lg = new LinearGradient(0, 0, 0, 25,0xFFfefefe,0xFFb2b2b2, TileMode.MIRROR);
           drawRoundRect(canvas, 10, 10, 200, 50,lg);
           LinearGradient lg2 = new LinearGradient(0, 0, 0, 25,0xFFfefefe,0xFFb2b2b2, TileMode.CLAMP);
           drawRoundRect(canvas, 10, 80, 200, 50,lg2);
           
           RadialGradient rg = new RadialGradient(50, 50, 75, 0xFFfefefe, 0xFF929292, TileMode.CLAMP);
           drawRoundRect(canvas, 10, 150, 100, 100,rg);
           SweepGradient sg = new SweepGradient(50, 50, 0xFFfefefe, 0xFF111111);
           drawRoundRect(canvas, 150, 150, 100, 100,sg);
        }
        
        private void drawRoundRect(Canvas canvas,int x, int y, int w, int h, Shader shader)
        {
            Paint p = new Paint();
            p.setAntiAlias(true);
            p.setShader(shader);
            canvas.save(Canvas.MATRIX_SAVE_FLAG);
            canvas.translate(x, y);
            RectF r = new RectF(0, 0, w, h);
            canvas.drawRoundRect(r, 5.0f, 5.0f, p);
            canvas.restore();
        }
        
    }
}
